<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>
<%@ taglib prefix="fun" uri="http://java.sun.com/jsp/jstl/functions"%>

<section class="content-header">
	<h1>
		模板管理<small>应用流程管理</small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
		<li><a href="#">应用流程管理</a></li>
		<li class="active">模板管理</li>
	</ol>
</section>
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<div class="box">
				<div class="box-header with-border">
					<div class="row">
						<form class="search-panel" action="workflow/template!list.action"
							name="search-form" result-container=".content-wrapper">
							<input type="text" name="entity.name"
								value="${entity.name }" class="form-control"
								placeholder="模板名称">
							<button type="button" class="btn btn-primary search-btn">搜索</button>
						</form>
					</div>
				</div>
				<div class="box-body no-padding">
					<div class="row">
						<div class="col-sm-12">
							<table class="table table-bordered">
								<tr>
									<th>
										<button title="全选"
											class="btn btn-default btn-sm checkbox-toggle"
											data-toggle="tooltip" data-placement="left">
											<i class="fa fa-square-o"></i>
										</button>
									</th>
									<th>排序</th>                   
				                	<th>模板名称</th>
				                    <th>模板说明</th>
				                    <th>模板类型</th>
				                    <th min-width="15%">操作</th>
								</tr>
								<c:if test="${empty list}">
								<tr>
									<td colspan="6">暂无数据！</td>
								</tr>
								</c:if>
								<c:forEach items='${list}' var="template">
									<tr>
										<td><input type="checkbox" value="${template.templateId}" name="delId"/></td>
										<td>
											<input type="text" name="templateOrders" value="${template.templateOrder}" style="width: 30px; height: 30px;"/>&nbsp;
					  						<input type="hidden" name="templateIds" value="${template.templateId}"/>
										</td>
										<td>${template.name}</td>
										<td>${template.descript}</td>
										<td>${template.type}</td>
										<td>
											<button type="button" title="修改" data-toggle="tooltip"
												data-placement="bottom" onclick="editTemplate('${template.recordId}')"
												class="btn btn-default btn-sm">
												<i class="fa fa-edit"></i>
											</button>
											<button type="button" title="删除" data-toggle="tooltip"
												data-placement="bottom"
												do-url="workflow/template!delete.action?id=${template.templateId}"
												load-url="workflow/template!list.action" confirm-msg="确定要删除吗？"
												class="btn btn-default btn-sm btn-open-confirm-win">
												<i class="fa fa-trash"></i>
											</button>
										</td>
									</tr>
								</c:forEach>
							</table>
						</div>
					</div>
				</div>
				<div class="box-footer">
					<!--分页区-->
					<div class="pagePanel">
						<thx:pages pageNo="page.curPage" total="page.totalPage" theme="number">
							<s:param name="entity.name" value="entity.name"></s:param>
						</thx:pages>
					</div>
					<!--底部操作区-->
					<div class="handlePanel">
						<a title="删除" class="a-btn btn-open-confirm-win btn-get-checkbox-ids" href="javascript:void(0);"
							do-url="workflow/template!delMulti.action?delId="
							load-url="workflow/template!list.action" confirm-msg="确定要删除吗？"
							style="margin-right: 5px"> 
							<span class="fa fa-trash"></span>
							<span class="text">删除</span>
						</a>
						<a title="新增" class="a-btn" href="javascript:void(0)" onclick="addTemplate()" style="margin-right: 5px">
							<span class="fa fa-plus"></span>
							<span class="text">新增</span>
						</a>
						<a title="保存排序" class="a-btn" href="javascript:void(0);" onclick="saveOrder()" > 
							<span class="fa fa-save"></span>
							<span class="text">保存排序</span>
						</a>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>
<script>

	$( function() {
		list.init();
		page.init();
	});
	
	function saveOrder(){
		var templateIds = [];
		var templateOrders = [];
	    $('input[name="templateIds"]').each(function(index, item){
	    	templateIds[templateIds.length] = $(item).val();
	    });
	    $('input[name="templateOrders"]').each(function(index, item){
    		templateOrders[templateOrders.length] = $(item).val();
	    });
		var options = {
			url : ctxPath + "/workflow/template!saveOrder.action?templateIds=" + templateIds + "&" + "templateOrders=" + templateOrders,
			type : 'post',
			success : function(msg) {
				if (msg == "success"){
					dialog.alert("排序保存成功!");
				}else{
					dialog.alert("排序保存失败!");
				}
			}
		};
		$.ajax(options);
	}
	 
	function addTemplate() {
		window.open("${pageContext.request.contextPath }/workflow/webOffice/input.jsp?FileType=.doc");
	} 
	
	function editTemplate(recordId) {
		window.open("${pageContext.request.contextPath }/workflow/webOffice/input.jsp?RecordID="+recordId);
	}
	
</script>
